﻿using System;
using System.Web;

namespace CBL
{
    public static class RequestExtensionProperties
    {
        public static string Keywords
        {
            get
            {
                return HttpContext.Current.Request.QueryString["keywords"] ?? string.Empty;
            }

        }

        public static DateTime Date
        {
            get
            {
                var param = HttpContext.Current.Request.QueryString["date"];
                return string.IsNullOrEmpty(param) ? default(DateTime) : param.ChangeType<DateTime>();
            }
        }

        public static int PageIndex
        {
            get
            {
                var param = HttpContext.Current.Request.QueryString["pageIndex"];
                return string.IsNullOrEmpty(param) ? 1 : param.ChangeType<int>();
            }

        }

        public static int PageSize
        {

            get
            {
                var param = HttpContext.Current.Request.QueryString["pageSize"];
                return string.IsNullOrEmpty(param) ? 1 : param.ChangeType<int>();
            }

        }

        public static bool ContainsPageIndex
        {
            get
            {
                return HttpContext.Current.Request.QueryString["pageIndex"] != null;
            }
        }

        public static bool IsAjax
        {
            get
            {
                var param = HttpContext.Current.Request.QueryString["isAjax"];
                if (HttpContext.Current.Request.Url.AbsolutePath.Equals("/default.aspx", StringComparison.InvariantCultureIgnoreCase))
                {
                    return (string.IsNullOrEmpty(param) && !ContainsPageIndex) || param.ChangeTypeToBoolean();
                }
                return !string.IsNullOrEmpty(param) && param.ChangeTypeToBoolean();
            }
        }

        public static long NewsId
        {
            get
            {
                var param = HttpContext.Current.Request["newsId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<long>();
            }
        }

        public static int TagId
        {
            get
            {
                var param = HttpContext.Current.Request["tagId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static string TagUrl
        {
            get { return HttpContext.Current.Request.QueryString["tagUrl"] ?? string.Empty; }
        }

        public static int CatId
        {

            get
            {
                var param = HttpContext.Current.Request["catId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }

        }

        public static string CatUrl
        {
            get
            {
                return HttpContext.Current.Request.QueryString["catUrl"] ?? string.Empty;
            }
        }

        public static string ParentCatUrl
        {

            get
            {
                return HttpContext.Current.Request.QueryString["parentCatUrl"] ?? string.Empty;
            }

        }

        public static string Url
        {
            get
            {
                return HttpContext.Current.Request.QueryString["url"] ?? string.Empty;
            }

        }

        public static int Day
        {
            get
            {
                var param = HttpContext.Current.Request.QueryString["day"];
                if (string.IsNullOrEmpty(param))
                    return -1;
                var result = param.ChangeType<int>();
                return result < 1 || result > 31 ? -1 : result;
            }
        }

        public static int Month
        {

            get
            {
                var param = HttpContext.Current.Request.QueryString["month"];
                if (string.IsNullOrEmpty(param))
                    return -1;
                var result = param.ChangeType<int>();
                return result < 1 || result > 12 ? -1 : result;
            }


        }

        public static int Year
        {

            get
            {
                var param = HttpContext.Current.Request.QueryString["year"];
                if (string.IsNullOrEmpty(param))
                    return -1;
                var result = param.ChangeType<int>();
                return result < 1900 ? -1 : result;
            }

        }

        public static int ZoneId
        {
            get
            {
                var param = HttpContext.Current.Request["zoneId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int VideoId
        {
            get
            {
                var param = HttpContext.Current.Request["videoId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int VideoZoneId
        {
            get
            {
                var param = HttpContext.Current.Request["videoZoneId"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int ImageWidth
        {
            get
            {
                var param = HttpContext.Current.Request["imageWidth"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int ImageHeight
        {
            get
            {
                var param = HttpContext.Current.Request["imageHeight"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int Top
        {
            get
            {
                var param = HttpContext.Current.Request["top"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int Type
        {
            get
            {
                var param = HttpContext.Current.Request["type"];
                return string.IsNullOrEmpty(param) ? -1 : param.ChangeType<int>();
            }
        }

        public static int VoteId
        {
            get
            {
                var param = HttpContext.Current.Request.QueryString["voteId"];
                if (string.IsNullOrEmpty(param))
                    return -1;
                return param.ChangeType<int>();
            }

        }

        public static string VoteItemIDs
        {
            get
            {
                return HttpContext.Current.Request.QueryString["VoteItemIDs"] ?? string.Empty;
            }
        }

        public static bool IsHomePage
        {
            get { return HttpContext.Current.Request.Url.AbsolutePath.Equals("/default.aspx", StringComparison.InvariantCultureIgnoreCase); }
        }
    }
}
